package com.usian.common.intercept;

import com.usian.utils.threadlocal.ThreadLocalUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminRefechIntercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String header = request.getHeader("newtoken");
        if (StringUtils.isNotBlank(header)) {
            response.setHeader("REETIME_TOKEN", header);
        }
         String id = request.getHeader("userId");
        if(StringUtils.isNotBlank(id)){
            ThreadLocalUtils.setUser(Integer.parseInt(id));
        }

        return true;
    }
}
